/**
* create by cyc on 2018/7/11
*/
~function(){
	var $content = $("#content");
	var $part1 = $("#content .c-part1");
	$(window).resize(alterPart1Height);
	alterPart1Height();
	function alterPart1Height(){
		$part1.height($(window).height() - parseFloat($content.css("top")));
	}
}()

/*btn*/
~function(){
	var headHeight = $("#header").height();//65
	var bgHeight = $("#content .bg").height();//430
	var partHeight = $("#content .part").height();//530
	var scrollDistance = $(window).height()+bgHeight-headHeight-1/2*($(window).height()-headHeight-partHeight);
	var btnLength = $("#content span.btn").length;
	$(window).resize(getScrollDistance);
	function getScrollDistance(){
		scrollDistance = $(window).height()+bgHeight-headHeight-1/2*($(window).height()-headHeight-partHeight);
	}
	for(var i=0;i<btnLength;i++){
		$("#content span.btn")[i].index=i;
	};
	$("#content span.btn").click(function(){
		if(this.index!=btnLength-1){
			var scrollbtn = scrollDistance + this.index*(bgHeight+partHeight);
		}else{
			var scrollbtn = $('html')[0].scrollHeight;	
		};
		$('html').animate({scrollTop:scrollbtn+'px'}, 800);
		
	});
	
}()

/*part3*/
~function(){
	var lis = $("#content .app-list ul li"),
		img = $("#content .app-imgs ul li"),
		index = 0,
		clickTime = 0,
		timer = null,
		length = lis.length;
		
	lis.click(function(){
		if(new Date()- clickTime>500){
			var clickIndex = $(this).index();
			change(function(){
				index = clickIndex;
			});
			clickTime = new Date();
		};	
	});
	auto();
	
	function auto(){
		timer = setInterval(function(){
			change(function(){
				index++;
				index %= length;
			});
		},2000)
	}
	function change(fn){
		lis.eq(index).removeClass("active"); 
		fn && fn();
		var imgTop = index * 324;
		img.css({ 'background-position-y': imgTop });
		lis.eq(index).addClass("active"); 
	}
	
	
}()
